package cn.tjd.smart_health.provider.service;


import cn.tjd.smart_health.api.CheckItemService;
import cn.tjd.smart_health.common.entity.CheckItem;
import cn.tjd.smart_health.common.pojo.PageSelect;
import cn.tjd.smart_health.provider.mapper.CheckItemMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

@DubboService
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;


    @Override
    public void saveCheckItem(CheckItem checkItem) {
        checkItemMapper.insert(checkItem);
    }

    @Override
    public List<CheckItem> findAllCheckItems() {
        return checkItemMapper.selectList(null);
    }

    @Override
    public PageSelect<CheckItem> findPage(Integer currentPage, Integer pageSize, String queryString) {
        Page<CheckItem> page = new Page<>(currentPage, pageSize);

        if (queryString == null) {
            checkItemMapper.selectPage(page, null);
        } else {
            QueryWrapper<CheckItem> queryWrapper=new QueryWrapper<CheckItem>();
            queryWrapper.like("name",queryString).
                    or().like("code",queryString);
            checkItemMapper.selectPage(page, queryWrapper);
        }
        PageSelect<CheckItem> pageSelect=new PageSelect<CheckItem>();
        pageSelect.setRows(page.getRecords());
        pageSelect.setTotal(page.getTotal());
        return pageSelect;
    }

    @Override
    public Integer deleteCheckItem(Integer id) {
        CheckItem checkItem = checkItemMapper.selectById(id);
        Integer result = checkItemMapper.deleteById(checkItem);
        return result;
    }

    @Override
    public CheckItem findCheckItemById(Integer id) {
        CheckItem checkItem = checkItemMapper.selectById(id);
        return checkItem;
    }

    @Override
    public Integer editCheckItem(CheckItem checkItem) {
        Integer result = checkItemMapper.updateById(checkItem);
        return result;
    }



}


